home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / extras / Direct3D / Tools / Maya40 / mydt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  4.3 KB  |  249 lines

  1.  
  2. #include "MyDt.h"
  3. #include <assert.h>
  4.  
  5.  
  6.  
  7. extern bool    g_bRelativeTexFile;
  8. extern bool    g_bExportAnimation;
  9. extern bool    g_bKeyframeAnimation;
  10. extern bool    g_bAnimateEverything;
  11. extern int        g_iFrameStep;
  12. extern int        g_iFlipU;
  13. extern int        g_iFlipV;
  14. extern bool    g_bExportPatches;
  15.  
  16. extern CArrayTable g_Arrays;
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. SMesh::SMesh() 
  25. {
  26.     m_kType = SMesh::UNKNOWN;
  27.  
  28.     m_nGroups = 0;
  29.     m_aGroups = NULL;
  30.  
  31.     m_nPoints = 0;
  32.     m_aPoints = NULL;
  33.  
  34.     m_nVertexColors = 0;
  35.     m_aVertexColors = NULL;
  36.  
  37.     m_nNormals = 0;
  38.     m_aNormals = NULL;
  39.  
  40.     m_nUVs = 0;
  41.     m_aUVs = NULL;
  42.  
  43.     m_nReps = 0;
  44.     m_aReps = NULL;
  45.  
  46.     m_nFaces = 0;
  47.     m_aFaces = NULL;
  48.  
  49.     m_nFaceIndices = 0;
  50.  
  51.     m_nBones = 0;
  52.     m_aBones = NULL;
  53.  
  54.     m_nMaxBonesPerFace = 0;
  55.     m_nMaxBonesPerPoint = 0;
  56. }
  57.  
  58.  
  59.  
  60. SMesh::~SMesh() 
  61. {
  62.     delete[] m_aReps;
  63.  
  64.     delete[] m_aPoints;
  65.     delete[] m_aNormals;
  66.     delete[] m_aUVs;
  67.     delete[] m_aVertexColors;
  68.  
  69.     for (UINT iFace = 0; iFace < m_nFaces; iFace++)
  70.     {
  71.         delete[] m_aFaces[iFace].m_aIndices;
  72.     }
  73.  
  74.     delete[] m_aFaces;
  75.  
  76.     delete[] m_aGroups;
  77.  
  78.     for (UINT iBone = 0; iBone < m_nBones; iBone++) 
  79.     {
  80.         delete[] m_aBones[iBone].m_afWeights;
  81.         delete[] m_aBones[iBone].m_aiPoints;
  82.     }
  83.  
  84.     delete[] m_aBones;
  85. }
  86.  
  87.  
  88. SFace::SFace()
  89. {
  90.     m_nIndices    = 0;
  91.     m_aIndices    = NULL;
  92.  
  93.     m_iGroup    = -1;
  94. }
  95.  
  96. SFace::~SFace() 
  97. {
  98. }
  99.  
  100.  
  101. SBone::SBone()
  102. {
  103.     m_szName = NULL;
  104.  
  105.     m_nReps = 0;
  106.  
  107.     m_nWeights = 0;
  108.     m_afWeights    = NULL;
  109.     m_aiPoints  = NULL;
  110.  
  111.     // set matrices to IDENITY
  112.     for (UINT i = 0; i < 4; i++)
  113.     {
  114.         for (UINT j = 0; j < 4; j++)
  115.         {
  116.             m_aafOffset[i][j] = 0.0f;
  117.         }
  118.  
  119.         m_aafOffset[i][i] = 1.0f;
  120.     }
  121. }
  122.  
  123. SBone::~SBone()
  124. {
  125. }
  126.  
  127. SAnim::SAnim()
  128. {
  129.     m_szName = NULL;
  130.  
  131.     m_nKeys = 0;
  132.     m_aKeys = NULL;
  133. }
  134.  
  135. SAnim::~SAnim()
  136. {
  137.     delete[] m_aKeys;
  138. }
  139.  
  140.  
  141.  
  142.  
  143. /*
  144.  
  145.  
  146.  
  147.  
  148. int    MyDtShapeGetControlPoints
  149.     (
  150.         MObject&    objInput, 
  151.         MObject&    objOutput, 
  152.         UINT*        pcVertices, 
  153.         DtVec3f**    prgVertices
  154.     ) 
  155. {
  156.     *pcVertices        = 0;
  157.     *prgVertices    = NULL;
  158.  
  159.     
  160.     assert(objInput.hasFn(MFn::kNurbsSurface) && objOutput.hasFn(MFn::kNurbsSurface));
  161.  
  162.  
  163.     MFnNurbsSurface    fnOutput(objOutput);
  164.     MFnNurbsSurface    fnInput(objInput);
  165.  
  166.  
  167.  
  168.     MPointArray rgCVs;
  169.  
  170.     fnInput.getCVs(rgCVs);
  171.  
  172.     *pcVertices        = rgCVs.length();
  173.     *prgVertices    = new DtVec3f[*pcVertices];
  174.  
  175.     if (!*prgVertices) 
  176.     {
  177.         *pcVertices    = 0;
  178.  
  179.         return 0;
  180.     }
  181.  
  182.     // WARNING:  Is this homogeneous coordinates? Should I divide w?
  183.     for (UINT iVertex = 0; iVertex < *pcVertices; iVertex++) 
  184.     {
  185.         (*prgVertices)[iVertex].vec[0]    = (float)rgCVs[iVertex][0];
  186.         (*prgVertices)[iVertex].vec[1]    = (float)rgCVs[iVertex][1];
  187.         (*prgVertices)[iVertex].vec[2]    = (float)rgCVs[iVertex][2];
  188.     }
  189.  
  190.  
  191.     // check for tweaks
  192.     MPlug    plgTweakLoc    = fnOutput.findPlug("tweakLocation");
  193.  
  194.     MObject    objTweakLocVal;
  195.  
  196.     plgTweakLoc.getValue(objTweakLocVal);
  197.  
  198.     if (!objTweakLocVal.isNull())    // tweak found
  199.     {    
  200.         MPlugArray    rgplgTweakLocConnections;
  201.  
  202.         plgTweakLoc.connectedTo(rgplgTweakLocConnections, true, false);        // get source plugs
  203.  
  204.         assert(rgplgTweakLocConnections.length() == 1);
  205.  
  206.         MObject    objTweak = rgplgTweakLocConnections[0].node();
  207.  
  208.         assert(objTweak.hasFn(MFn::kTweak));
  209.  
  210.         MFnGeometryFilter    fnTweak(objTweak);
  211.  
  212.         bool    bRelativeTweak;
  213.  
  214.         fnTweak.findPlug("relativeTweak").getValue(bRelativeTweak);
  215.  
  216.         if (!bRelativeTweak) 
  217.             cout << "\t\tWARNING: Encountered an absolute tweak; treating as relative!" << endl;
  218.  
  219.         MPlug plgOffsets = fnTweak.findPlug("plist")[0].child(0);
  220.  
  221.  
  222.         //    WARNING: Seems like Maya doesn't initialize it's numElements properly!!
  223. //        assert((int)plgOffsets.numElements() == cVertices);
  224.         if ((int)plgOffsets.numElements() != *pcVertices)
  225.             cout << "\t\tWARNING: tweak count doesn't match vertex count!" << endl;
  226.  
  227.         float    fEnvelope    = fnTweak.envelope();
  228.  
  229.         for (UINT iVertex = 0; iVertex < *pcVertices; iVertex++) 
  230.         {
  231.             DtVec3f    vecOffset;
  232.  
  233.             plgOffsets.elementByLogicalIndex(iVertex).child(0).getValue(vecOffset.vec[0]);
  234.             plgOffsets.elementByLogicalIndex(iVertex).child(1).getValue(vecOffset.vec[1]);
  235.             plgOffsets.elementByLogicalIndex(iVertex).child(2).getValue(vecOffset.vec[2]);
  236.  
  237.             (*prgVertices)[iVertex].vec[0]    += fEnvelope * vecOffset.vec[0];
  238.             (*prgVertices)[iVertex].vec[1]    += fEnvelope * vecOffset.vec[1];
  239.             (*prgVertices)[iVertex].vec[2]    += fEnvelope * vecOffset.vec[2];
  240.         }
  241.     }
  242.             
  243.             
  244.  
  245.     return 1;
  246. }
  247.  
  248.  
  249. */